<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.min.css"/>
		<style type="text/css">
			body{
				background-color: #dbdcdc;
			}
			.save:hover{
				background-color: #000000;
			}
		</style>
	</head>
	<body>
		<div style="margin-right: 45%;" id="">
		<br>
		<form style="text-align: right;" action="" method="">
			<h1 style="margin-right: 4%;">注册新用户</h1>
			<br><br>
			<label style="font-size: 20px;">用户名</label>
			<input style="border-radius:5px 5px 5px 5px;border: 1px solid #ccc;height: 30px;width: 25%;" type="text" name="user" id="" value="" />
			<br><br>
			<br>
			<label style="font-size: 20px;">密码：</label>
			<input style="border-radius:5px 5px 5px 5px;border: 1px solid #ccc; height: 30px;width: 25%;" type="password" name="psd" id="" value="" />
			<br><br><br>
			<label style="font-size: 20px;">确认密码：</label>
			<input style="border-radius:5px 5px 5px 5px;border: 1px solid #ccc; height: 30px;width: 25%;" type="password" name="c_psd" id="" value="" />
			<br><br><br>
			<button style="height: 30px;width: 25%;background-color: #1B6D85;color: white;font-size: 20px;" type="button" onclick="save()" class="save">保存</button>
		</form>	
		</div>
		<script src="../js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
		<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			//获取登入界面传来的用户数据
			let arr_data = JSON.parse(localStorage.getItem("arr_data"));
			//保存数据
			function save(){
				let user = $("input[name='user']").val();
				let psd = $("input[name='psd']").val();
				let c_psd = $("input[name='c_psd']").val();
				let new_user=
					{
						user:user,
						psd:psd,
					};
				console.log(user,psd,c_psd)
				for(let index in arr_data){
					let item = arr_data[index];
					if(user === item.user){
						alert("用户以被注册");
						break;
					}else if(psd.length !== 6){
						alert("密码必须为六位");
						break;
					}else if(psd !== c_psd){
						alert("两次密码输入不一致");
						break;
					}
					arr_data.push(new_user);
					console.log(arr_data);
					alert("注册成功");
					//将注册成功数据传回登入界面
					localStorage.setItem("new_user",JSON.stringify(arr_data));
					window.location.href="login.html";
					break;
				}
			}
		</script>
	</body>
</html>
